<?php
namespace app\api\controller;

use app\api\service\OrderService;
use app\api\service\VpayService;
use app\common\controller\Api;
use think\facade\Log;
use think\facade\Cache;


class App extends Api
{

    public function heart(VpayService $vpayService) 
    {
        try{
            $vpayService->checkSign($this->request->get());
        }catch(\Exception $e){
            $this->error($e->getMessage());
        }
        $vpayService->setHeartbeat();
        $this->success('心跳成功', '', 200);
    }

    public function push(OrderService $orderService, VpayService $vpayService)  {
        $data= $this->request->get();
        $vpayService->setHeartbeat();
        try{
            $vpayService->checkSign($data);
            $orderService->callback($data['type'], $data['price'], $data['time']?? null);
        }catch (\Exception $e){
            $this->error($e->getMessage());
        }
        $this->success('推送成功', '', 200);
    }
    
}